//
//  PhotosSettingView.m
//  MovieDate
//
//  Created by 杨运涛 on 16/3/15.
//  Copyright © 2016年 MovieDate. All rights reserved.
//

#define IMG_MID 5
#define IMG_WIDTH ([UIScreen mainScreen].bounds.size.width - IMG_MID * 4) / 3

#import "PhotosSettingView.h"

@interface PhotosSettingView ()


@end

@implementation PhotosSettingView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        AlbumImageView *img1 = [[AlbumImageView alloc] initWithFrame:CGRectMake(IMG_MID, IMG_MID, IMG_WIDTH * 2 + IMG_MID, IMG_WIDTH * 2 + IMG_MID)];
        [img1 setImage:[UIImage imageNamed:@"icon_add_photo"]];
        [img1 setContentMode:UIViewContentModeCenter];
        [img1.layer setBorderColor:[UIColor lightGrayColor].CGColor];
        [img1.layer setCornerRadius:5.0f];
        [img1.layer setMasksToBounds:YES];
        [img1.layer setBorderWidth:0.5f];
        [img1 setUserInteractionEnabled:YES];
        UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapTouchImageAction:)];
        [img1 addGestureRecognizer:tap1];
        _pImg1 = img1;
        [self addSubview:img1];
        
        AlbumImageView *img2 = [[AlbumImageView alloc] initWithFrame:CGRectMake(img1.frame.size.width + IMG_MID * 2, IMG_MID, IMG_WIDTH, IMG_WIDTH)];
        [img2 setImage:[UIImage imageNamed:@"bg_photo1"]];
//        [img2.layer setBorderColor:[UIColor lightGrayColor].CGColor];
//        [img2.layer setCornerRadius:3.0f];
//        [img2.layer setMasksToBounds:YES];
//        [img2.layer setBorderWidth:0.5f];
        [img2 setUserInteractionEnabled:YES];
        UITapGestureRecognizer *tap2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapTouchImageAction:)];
        [img2 addGestureRecognizer:tap2];
        _pImg2 = img2;
        [self addSubview:img2];
        
        AlbumImageView *img3 = [[AlbumImageView alloc] initWithFrame:CGRectMake(img2.frame.origin.x, img2.frame.origin.y + img2.frame.size.height + IMG_MID, IMG_WIDTH, IMG_WIDTH)];
        [img3 setImage:[UIImage imageNamed:@"bg_photo2"]];
//        [img3.layer setBorderColor:[UIColor lightGrayColor].CGColor];
//        [img3.layer setCornerRadius:3.0f];
//        [img3.layer setMasksToBounds:YES];
//        [img3.layer setBorderWidth:0.5f];
        [img3 setUserInteractionEnabled:YES];
        UITapGestureRecognizer *tap3 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapTouchImageAction:)];
        [img3 addGestureRecognizer:tap3];
        _pImg3 = img3;
        [self addSubview:img3];
        
        AlbumImageView *img4 = [[AlbumImageView alloc] initWithFrame:CGRectMake(IMG_MID, img1.frame.size.height + IMG_MID * 2, IMG_WIDTH, IMG_WIDTH)];
        [img4 setImage:[UIImage imageNamed:@"bg_photo3"]];
//        [img4.layer setBorderColor:[UIColor lightGrayColor].CGColor];
//        [img4.layer setCornerRadius:3.0f];
//        [img4.layer setMasksToBounds:YES];
//        [img4.layer setBorderWidth:0.5f];
        [img4 setUserInteractionEnabled:YES];
        UITapGestureRecognizer *tap4 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapTouchImageAction:)];
        [img4 addGestureRecognizer:tap4];
        _pImg4 = img4;
        [self addSubview:img4];
        
        AlbumImageView *img5 = [[AlbumImageView alloc] initWithFrame:CGRectMake(IMG_WIDTH + IMG_MID * 2, img4.frame.origin.y, IMG_WIDTH, IMG_WIDTH)];
        [img5 setImage:[UIImage imageNamed:@"bg_photo4"]];
//        [img5.layer setBorderColor:[UIColor lightGrayColor].CGColor];
//        [img5.layer setCornerRadius:3.0f];
//        [img5.layer setMasksToBounds:YES];
//        [img5.layer setBorderWidth:0.5f];
        [img5 setUserInteractionEnabled:YES];
        UITapGestureRecognizer *tap5 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapTouchImageAction:)];
        [img5 addGestureRecognizer:tap5];
        _pImg5 = img5;
        [self addSubview:img5];
        
        AlbumImageView *img6 = [[AlbumImageView alloc] initWithFrame:CGRectMake(IMG_WIDTH + IMG_MID + img5.frame.origin.x, img4.frame.origin.y, IMG_WIDTH, IMG_WIDTH)];
        [img6 setImage:[UIImage imageNamed:@"bg_photo5"]];
//        [img6.layer setBorderColor:[UIColor lightGrayColor].CGColor];
//        [img6.layer setCornerRadius:3.0f];
//        [img6.layer setMasksToBounds:YES];
//        [img6.layer setBorderWidth:0.5f];
        [img6 setUserInteractionEnabled:YES];
        UITapGestureRecognizer *tap6 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapTouchImageAction:)];
        [img6 addGestureRecognizer:tap6];
        _pImg6 = img6;
        [self addSubview:img6];
    }
    
    return self;
}

- (void)tapTouchImageAction:(UITapGestureRecognizer *)tapgestureRecognizer
{
    AlbumImageView *img = (AlbumImageView *)tapgestureRecognizer.view;
    _pImgSelect = img;
    if ([self.delegate respondsToSelector:@selector(selSelectImg:)]) {
        [self.delegate selSelectImg:img];
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
